package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    /**
     * 查询总记录数
     * @return  总记录数
     */
    @Select("select count(*) from emp")
    Integer getCount();

    @Select("select * from emp limit #{startIndex}, #{pageSize}")
    List<Emp> list(Integer startIndex, Integer pageSize);

//    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp")
    List<Emp> page(String name, Integer gender, LocalDate begin, LocalDate end);

    void delete(List<Integer> ids);

    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) VALUES " +
            "(#{username} , #{name} , #{gender} , #{image} , #{job} , #{entrydate} , #{deptId} , #{createTime} , #{updateTime} )")
    void save(Emp emp);

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp where id = #{id}")
    Emp getById(Integer id);

    void update(Emp emp);

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time" +
            " from emp where username = #{username} and password = #{password} ")
    Emp getByUsernameAndPassword(Emp emp);

    /**
     * 根据部门id删除员工
     * @param deptId    部门id
     */
    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
